# coding=utf-8
# -*- coding: UTF-8 -*-
#
# This file is part of the kernelstudio package.
#
# (c) 2014-2025 zlin <admin@kernelstudio.com>
#
# For the full copyright and license information, please view the LICENSE file
# that was distributed with this source code.

import typing as t

from flask import Blueprint
from flask_restful.utils import OrderedDict

from ksai.context import ApplicationInitializer, Application
from ksai.web.exceptions import register_json_exception_handlers
from ksai.web.json import json_output_response
from ksai.web.restful import ParametersBindableResource, ApiEndpoint


class ApiResource(ParametersBindableResource):
    pass


endpoint = Blueprint('api', __name__, url_prefix="/api", template_folder='views')
interceptor = ApiEndpoint(endpoint)
interceptor.representations = OrderedDict([('application/json', json_output_response)])


class ApiEndpointInitializer(ApplicationInitializer):

    def initialize(self, app: Application) -> t.Any:
        register_json_exception_handlers(app)
        app.register_blueprint(endpoint)
